class Solution(object):
    def wiggleMaxLength(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        state = 0
        length = 1
        for i in range(1, n):
            if state == 0:
                if nums[i] > nums[i - 1]:
                    state = 1
                    length += 1
                else:
                    if nums[i] < nums[i - 1]:
                        state = 2
                        length += 1
            else:
                if state == 1:
                    if nums[i] < nums[i - 1]:
                        state = 2
                        length += 1
                else:
                    if nums[i] > nums[i - 1]:
                        state = 1
                        length += 1
        return length


data = Solution()
nums = [1, 17, 5, 10, 13, 15, 10, 5, 16, 8]
print(data.wiggleMaxLength(nums))
